package com.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mapper.PhotosMapper;
import com.model.Photos;
import com.util.PageBean;
@Service
public class PhotosServiceImpl implements PhotosService{
        
	@Autowired
	private PhotosMapper photosMapper;

	//查询多条记录
	public List<Photos> queryPhotosList(Photos photos,PageBean page) throws Exception {
		Map<String, Object> map =getQueryMap(photos, page);
		
		List<Photos> getPhotos = photosMapper.query(map);
		
		return getPhotos;
	}
	
	//得到记录总数
	@Override
	public int getCount(Photos photos) {
		Map<String, Object> map = getQueryMap(photos, null);
		int count = photosMapper.getCount(map);
		return count;
	}
	
	private Map<String, Object> getQueryMap(Photos photos,PageBean page){
		Map<String, Object> map = new HashMap<String, Object>();
		if(photos!=null){
			map.put("id", photos.getId());
			map.put("wid", photos.getWid());
			map.put("addr", photos.getAddr());
			map.put("sort", photos.getSort());
			map.put("condition", photos.getCondition());

		}
		PageBean.setPageMap(map, page);
		return map;
	}
		
	//添加
	public int insertPhotos(Photos photos) throws Exception {
		return photosMapper.insertPhotos(photos);
	}

	//根据ID删除
	public int deletePhotos(int id) throws Exception {
		return photosMapper.deletePhotos(id);
	}

	//更新
	public int updatePhotos(Photos photos) throws Exception {
		return photosMapper.updatePhotos(photos);
	}
	
	//根据ID得到对应的记录
	public Photos queryPhotosById(int id) throws Exception {
		Photos po =  photosMapper.queryPhotosById(id);
		return po;
	}
}

